Using Deploy resource(Chef)

Rishabh Jain 11 years ago
parent
commit
6618b2cb09

+ 0 - 45
deployment/README.md

@@ -1,45 +0,0 @@
1
-Make sure you have Vagrant and Virtualbox(Not necessary, if deploying to AWS) installed.
2
-Install librarian-chef gem
3
-
4
-    gem install librarian-chef
5
-
6
-And Vagrant plugins
7
-
8
-    vagrant plugin install vagrant-aws
9
-    vagrant plugin install vagrant-omnibus
10
-
11
-Move to `/deployment` and run
12
-
13
-    librarian-chef install
14
-
15
-This will install all the cookbooks mentioned in Cheffile.
16
-
17
-To install Huginn on AWS, fill the Vagrantfile with your account details and run
18
-
19
-    vagrant up ec2 --provider=aws
20
-
21
-To install it on a virtualbox VM:
22
-
23
-    vagrant up vb
24
-
25
-It'll install huginn and get the server started. You can now go to `yourserver.com/3000` to use huginn if you are in virtualbox. On ec2, pointing to public DNS will let you access huginn. Huginn will be at `/home/huginn/huginn`. A new dedicated user will be created for managing huginn with username `huginn` and password `huginn`. To ssh into ec2: 
26
-
27
-    vagrant ssh ec2
28
-
29
-Similarly, to ssh into VirtualBox
30
-
31
-    vagrant ssh vb
32
-    
33
-After ssh-ing into ec2, you can start(its already running), stop or restart huginn by
34
-    
35
-    sudo start huginn
36
-    sudo stop huginn
37
-    sudo restart huginn
38
-
39
-To terminate ec2 instance:
40
-
41
-    vagrant destroy ec2
42
-
43
-Similarly, to destroy VirtualBox VM
44
-
45
-    vagrant destroy vb

+ 1 - 10
deployment/Vagrantfile

@@ -43,16 +43,7 @@ Vagrant.configure("2") do |config|
43 43
       chef.roles_path = "roles"
44 44
       chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
45 45
       chef.add_role("huginn_production")
46
-      chef.json = {
47
-    "mysql"=> {
48
-      "server_root_password" => "",
49
-      "server_repl_password" => "",
50
-      "server_debian_password"=> ""
51
-    },
52
-    "nginx" => {
53
-       'init_style' => "upstart"
54
-    }
55
-    }
46
+    
56 47
     end
57 48
   end
58 49
 end

+ 0 - 0
deployment/nodes/.gitignore


+ 11 - 0
deployment/roles/huginn_production.json

@@ -8,6 +8,17 @@
8 8
 
9 9
 "description" : "Huginn Production Environment",
10 10
 
11
+"default_attributes" : {
12
+  "mysql": {
13
+    "server_root_password": "",
14
+    "server_repl_password": "",
15
+    "server_debian_password": ""
16
+  },
17
+    "nginx" : {
18
+       "init_style" : "upstart"
19
+    }
20
+},
21
+
11 22
 "run_list":[
12 23
              "recipe[git]",
13 24
              "recipe[apt]",

deployment/site-cookbooks/huginn_production/files/default/.env.example → deployment/site-cookbooks/huginn_production/files/default/env.example


+ 3 - 3
deployment/site-cookbooks/huginn_production/files/default/nginx.conf

@@ -8,18 +8,18 @@ events {
8 8
 
9 9
 http {
10 10
   upstream huginn_server {
11
-    server unix:/home/huginn/huginn/tmp/sockets/unicorn.sock;
11
+    server unix:/home/huginn/shared/tmp/sockets/unicorn.sock;
12 12
 }
13 13
 
14 14
   server {
15 15
     listen 80;
16 16
     server_name _;
17 17
     keepalive_timeout 5;
18
-    root /home/huginn/huginn/public;
18
+    root /home/huginn/current/public;
19 19
     try_files $uri/index.html $uri.html $uri @app;
20 20
     error_page 500 502 503 504 /500.html;
21 21
     location = /500.html {
22
-      root /home/huginn/huginn/public;
22
+      root /home/huginn/current/public;
23 23
     }
24 24
     location @app {
25 25
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

+ 3 - 3
deployment/site-cookbooks/huginn_production/files/default/unicorn.rb

@@ -1,9 +1,9 @@
1
-app_path = "/home/huginn/huginn"
1
+app_path = "/home/huginn/current"
2 2
 
3 3
 worker_processes 2
4 4
 preload_app true
5 5
 timeout 180
6
-listen '/home/huginn/huginn/tmp/sockets/unicorn.sock'
6
+listen '/home/huginn/shared/tmp/sockets/unicorn.sock'
7 7
 
8 8
 working_directory app_path
9 9
 
@@ -14,7 +14,7 @@ stderr_path "log/unicorn_out.log"
14 14
 stdout_path "log/unicorn_err.log"
15 15
 
16 16
 # Set master PID location
17
-pid '/home/huginn/huginn/tmp/pids/unicorn.pid'
17
+pid '/home/huginn/shared/tmp/pids/unicorn.pid'
18 18
 
19 19
 before_fork do |server, worker|
20 20
   ActiveRecord::Base.connection.disconnect!

+ 58 - 69
deployment/site-cookbooks/huginn_production/recipes/default.rb

@@ -2,7 +2,6 @@ include_recipe 'apt'
2 2
 include_recipe 'build-essential'
3 3
 
4 4
 user "huginn" do
5
-  action :create
6 5
   system true
7 6
   home "/home/huginn"
8 7
   password "$6$ZwO6b.6tij$SMa8UIwtESGDxB37NwHsct.gJfXWmmflNbH.oypwJ9y0KkzMkCdw7D14iK7GX9C4CWSEcpGOFUow7p01rQFu5."
@@ -13,66 +12,15 @@ end
13 12
 
14 13
 group "huginn" do
15 14
   members ["huginn"]
16
-  action :create
17 15
 end
18 16
 
19 17
 %w("ruby1.9.1" "ruby1.9.1-dev" "libxslt-dev" "libxml2-dev" "curl" "libshadow-ruby1.8").each do |pkg|
20
-  package pkg do
21
-    action :install
22
-  end
23
-end
24
-
25
-git "/home/huginn/huginn" do
26
-  repository 'git://github.com/cantino/huginn.git'
27
-  reference 'master'
28
-  action :sync
29
-  user "huginn"
18
+  package("#{pkg}")
30 19
 end
31 20
 
32 21
 gem_package("rake")
33 22
 gem_package("bundle")
34 23
 
35
-cookbook_file "/etc/nginx/nginx.conf" do
36
-  source "nginx.conf"
37
-  owner "huginn"
38
-end
39
-
40
-directory "/home/huginn/huginn/tmp" do
41
-  action :create
42
-  owner "huginn"
43
-  recursive true
44
-end
45
-
46
-directory "/home/huginn/huginn/log" do
47
-  action :create
48
-  owner "huginn"
49
-  recursive true
50
-end
51
-
52
-cookbook_file "/home/huginn/huginn/config/unicorn.rb" do
53
-  source "unicorn.rb"
54
-  mode "644"
55
-  owner "huginn"
56
-end
57
-
58
-cookbook_file "home/huginn/huginn/Gemfile" do
59
-  source "Gemfile"
60
-  mode "644"
61
-  owner "huginn"
62
-end
63
-
64
-cookbook_file "home/huginn/huginn/.env" do
65
-  source ".env.example"
66
-  mode "666"
67
-  owner "huginn"
68
-end
69
-
70
-cookbook_file "home/huginn/huginn/Procfile" do
71
-  source "Procfile"
72
-  mode "444"
73
-  owner "huginn"
74
-end
75
-
76 24
 service "nginx" do
77 25
   action :start
78 26
 end
@@ -80,24 +28,65 @@ end
80 28
 bash "Setting huginn user with NOPASSWD option" do
81 29
   cwd "/etc/sudoers.d"
82 30
   code <<-EOH
83
-    touch huginn
84
-    chmod 0440 huginn 
31
+    touch huginn && chmod 0440 huginn 
85 32
     echo "huginn ALL=(ALL) NOPASSWD:ALL" >> huginn
86 33
   EOH
87 34
 end
88 35
 
89
-bash "huginn dependencies" do
90
-  cwd "/home/huginn/huginn"
36
+deploy "/home/huginn" do
37
+  repo "https://github.com/cantino/huginn.git"
91 38
   user "huginn"
92
-  code <<-EOH
93
-    export LANG="en_US.UTF-8"
94
-    export LC_ALL="en_US.UTF-8"
95
-    sudo bundle install
96
-    sed -i s/REPLACE_ME_NOW\!/$(sudo rake secret)/ .env
97
-    sudo rake db:create
98
-    sudo rake db:migrate
99
-    sudo rake db:seed
100
-    sudo foreman export upstart /etc/init -a huginn -u huginn
101
-    sudo start huginn
102
-    EOH
103
-end
39
+  environment "RAILS_ENV" => "production"
40
+  keep_releases 5
41
+  create_dirs_before_symlink []
42
+  symlinks "log" => "log"
43
+  symlink_before_migrate({})
44
+  rollback_on_error true
45
+  before_symlink do
46
+    %w(config log tmp).each do |dir|
47
+      directory "/home/huginn/shared/#{dir}" do
48
+      owner "huginn"
49
+      recursive true
50
+      end
51
+    end
52
+    directory("/home/huginn/shared/tmp/pids")
53
+    directory("/home/huginn/shared/tmp/sockets")
54
+    cookbook_file "/etc/nginx/nginx.conf" do
55
+      source "nginx.conf"
56
+      owner "huginn"
57
+    end
58
+    %w(Procfile unicorn.rb Gemfile).each do |file|
59
+      cookbook_file "/home/huginn/shared/config/#{file}" do
60
+      owner "huginn"
61
+      action :create_if_missing
62
+      end
63
+    end
64
+    cookbook_file "home/huginn/shared/config/.env" do
65
+    source "env.example"
66
+    mode "666"
67
+    owner "huginn"
68
+    action :create_if_missing
69
+    end
70
+  end
71
+  before_restart do
72
+    bash "huginn dependencies" do
73
+      cwd "/home/huginn/current"
74
+      user "huginn"
75
+      code <<-EOH
76
+      export LANG="en_US.UTF-8"
77
+      export LC_ALL="en_US.UTF-8"
78
+      ln -nfs /home/huginn/shared/config/Gemfile ./Gemfile
79
+      ln -nfs /home/huginn/shared/config/Procfile ./Procfile
80
+      ln -nfs /home/huginn/shared/config/.env ./.env
81
+      ln -nfs /home/huginn/shared/config/unicorn.rb ./config/unicorn.rb
82
+      sudo bundle install
83
+      sed -i s/REPLACE_ME_NOW\!/$(sudo rake secret)/ .env
84
+      sudo rake db:create
85
+      sudo rake db:migrate
86
+      sudo rake db:seed
87
+      sudo foreman export upstart /etc/init -a huginn -u huginn -l log
88
+      sudo start huginn
89
+      EOH
90
+    end
91
+  end
92
+end

+ 6 - 0
deployment/solo.rb

@@ -0,0 +1,6 @@
1
+file_cache_path           "/tmp/chef-solo"
2
+data_bag_path             "/tmp/chef-solo/data_bags"
3
+encrypted_data_bag_secret "/tmp/chef-solo/data_bag_key"
4
+cookbook_path             [ "/tmp/chef-solo/site-cookbooks",
5
+                            "/tmp/chef-solo/cookbooks" ]
6
+role_path                 "/tmp/chef-solo/roles"